//package io.github.yotta.export.core.export.impl;
//
//import cn.afterturn.easypoi.excel.entity.ExportParams;
//import cn.afterturn.easypoi.excel.export.ExcelBatchExportService;
//import com.google.common.util.concurrent.ThreadFactoryBuilder;
//import io.github.yotta.common.api.model.ApiPageRequest;
//import io.github.yotta.common.api.model.Paging;
//import io.github.yotta.export.core.export.ExcelDataExporter;
//import io.github.yotta.export.core.model.ExecuteContext;
//import io.github.yotta.export.core.provider.FileProvider;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.poi.ss.usermodel.Workbook;
//
//import java.io.IOException;
//import java.io.OutputStream;
//import java.util.List;
//import java.util.concurrent.ExecutorService;
//import java.util.concurrent.Executors;
//
///**
// * @author yotta
// * @date 2023/10/24 16:57
// */
//@Slf4j
//@Deprecated
//public class EasyPoiExcelDataExporterExecutor extends AbstractExporterExecutor {
//
//    public EasyPoiExcelDataExporterExecutor(ExecutorService executorService, FileProvider fileProvider) throws IOException {
//        super(executorService, fileProvider);
//    }
//
//
//    public EasyPoiExcelDataExporterExecutor(FileProvider fileProvider) throws IOException {
//        this(Executors.newFixedThreadPool(5,
//                new ThreadFactoryBuilder()
//                        .setNameFormat("DataExportExecutorThread-%d")
//                        .setDaemon(false).build()), fileProvider);
//    }
//
//    @Override
//    protected <R extends ApiPageRequest, M, C extends ExecuteContext> Long doExport(R exportParam,
//                                                                                    ExcelDataExporter<M, R, C> xlsxDataExporter,
//                                                                                    C dataExecuteContext,
//                                                                                    OutputStream outputStream) throws IOException {
//
//        long exportedCount = 0L;
//        final String sheetName = xlsxDataExporter.sheetName(exportParam, dataExecuteContext);
//        final ExcelBatchExportService excelBatchExportService = buildExcelBatchExportService(exportParam, xlsxDataExporter.modelClass(), sheetName);
//        while (true) {
//            Integer pageNo = exportParam.getPageNo();
//            // 分页去数据库查询数据 这里可以去数据库查询每一页的数据
//            final Paging<M> pageResult = xlsxDataExporter.exportData(exportParam, dataExecuteContext);
//            List<M> dataSet = pageResult.getData();
//            if (CollectionUtils.isEmpty(dataSet)) {
//                break;
//            } else {
//                excelBatchExportService.write(dataSet);
//                exportParam.setPageNo(++pageNo);
//                exportedCount += dataSet.size();
//            }
//        }
//        final Workbook workbook = excelBatchExportService.close();
//        workbook.write(outputStream);
//        return exportedCount;
//    }
//
//    private <M> ExcelBatchExportService buildExcelBatchExportService(ApiPageRequest xlsxExportParam, Class<M> modelClass, String sheetName) {
//        ExcelBatchExportService excelBatchExportService = new ExcelBatchExportService();
//        excelBatchExportService.init(toExportParams(xlsxExportParam, sheetName), modelClass);
//        return excelBatchExportService;
//    }
//
//    protected ExportParams toExportParams(ApiPageRequest xlsxExportParam, String sheetName) {
//        final ExportParams exportParams = new ExportParams();
//        exportParams.setSheetName(sheetName);
//        return exportParams;
//    }
//}
